#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int ans, n, a[maxn], c[maxn];
inline void dfs (int i, int lblue, int lred) {
	if (i > n) {
		int res = 0;
		for (int j = 1; j <= n; j++) res += c[j];
		ans = max(ans, res);
		return ;
	}
	c[i] = ((a[i] == lblue) ? a[i] : 0);
	dfs (i + 1, a[i], lred);
	c[i] = ((a[i] == lred) ? a[i] : 0);
	dfs (i + 1, lblue, a[i]);;
	c[i] = 0;
}
inline int read () {
	int x = 0, k = 1;
	char ch = getchar ();
	while (!isdigit (ch) && ch != '-') ch = getchar ();
	if (ch == '-') {
		k = -1;
		ch = getchar ();
	}
	while (isdigit (ch)) {
		x = x * 10 + ch - '0';
		ch = getchar ();
	}
	return x * k;
}
int main () {
	freopen ("color.in", "r", stdin);
	freopen ("color.out", "w", stdout);
	int T = read ();
	while (T--) {
		ans = 0;
		n = read ();
		for (int i = 1; i <= n; i++) a[i] = read ();
		dfs (1, -1, -1);
		cout << ans << '\n';
	}
	return 0;
}
